//
//  BaseModel.m
//  news
//
//  Created by imacbookair on 16/3/8.
//  Copyright © 2016年 imacbookair. All rights reserved.
//

#import "BaseModel.h"

@implementation BaseModel

/// 初始化
- (instancetype)initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        [self setValuesForKeysWithDictionary:dic];
        
    }
    return self;
}

/// 便利构造器
+ (instancetype)modelWithDic:(NSDictionary *)dic
{
    id m = [[[self class] alloc]initWithDic:dic];
    return m;
}

/// 容错方法
- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}
/// 数组 + 字典 -> 数组 + 对象
+ (NSMutableArray *)modelHanderWithArray:(NSArray *)arr
{
    // 1. 创建空数组 保存处理后的model对象
    NSMutableArray *mArr = [NSMutableArray array];
    // 2. 便利传入的数组参数 得到每个字典信息
    for (NSDictionary *dic in arr) {
        // 3. 使用KVC转化为对象
        id m = [[self class]modelWithDic:dic];
        // 4. 添加到数组
        [mArr addObject:m];
    }
    return mArr;
}
@end
